package sample;

import javax.naming.InsufficientResourcesException;
import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class Utils {
    public static Map<Integer,String> getSongWords() throws IOException {
        Map<Integer,String> map = new HashMap<>();
        File file = new File("/home/hankun/project/MusicApplication/songwords/wuqi.txt");
        FileReader fileReader =  new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        System.out.println(fileReader.toString());
        StringBuilder stringBuilder = new StringBuilder();
        String str ="";
        while ( (str = bufferedReader.readLine()) != null)
            stringBuilder.append(str);
        String s = stringBuilder.toString();
        s = s.replaceAll("\\]","");
        String[] splits = s.split("\\[");
        System.out.println(splits.toString());
        for (int i = 1; i <splits.length ; i++) {
            String timeStr = splits[i].substring(0,8);
            Integer time  = anaylzeTime(timeStr);
            map.put(time,splits[i].substring(8));
        }
        return map;
    }
    public static Integer anaylzeTime(String time){
        int minuts = Integer.valueOf(time.substring(0,2));
        int seconds = Integer.valueOf(time.substring(3,5));
        int mill = Integer.valueOf(time.substring(7));
        return Math.round((minuts*60+seconds));
    }
}
